//index.js
//获取应用实例
const app = getApp()
let Axios = require('../../../common/js/ajax.js');
let WxValidate = require('../../../common/js/WxValidate.js'); //表单验证
let Mtils = require('../../../common/js/Mtils.min.js');
Mtils = Mtils.Mtils
Page({
	data: {
		openid: '',
		shopName: '',
		shopAvatarUrl: '',
		curentNav: 2, //当前导航
		money: 0,
		store_id: 0,
		isIpx:app.globalData.isIpx?true:false
	},
	//事件处理函数	
	onLoad: function(e) {
		var _this = this;
		this.initValidate()
		this.uid = app.globalData.uid || ''
		this.Md5 = Mtils.security.hex_md5(this.uid) + app.globalData.secret;
		this.Md5 = Mtils.security.hex_md5(this.Md5);
		this.timesp = Mtils.now();
		_this.setData({
			store_id: e.store_id
		})

	},
	onReady: function() {
		wx.setNavigationBarTitle({
			title: '追缴保证金'
		})
	},
	bindIputMoney: function() {
		//console.log(e.detail)
	},
	submit: function(e) {
		console.log(e.detail)
		var params = e.detail.value
		if (!this.WxValidate.checkForm(params)) {
			const error = this.WxValidate.errorList[0]
			this.showModal(error)
			return false
		}
		this.submitInfo(params);
	},
	submitInfo: function(e) {
		var _this = this
		var CONST = {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
			store_id: this.data.store_id
		}
		var obj = Object.assign(e, CONST);
		Axios.post(app.globalData.baseUrl + 'App/Capital/Cash/pay_bond_money',
			obj, (res) => {
				console.log(res)
				if (res.status == 1) {
					var data = res.info
					wx.requestPayment({
						timeStamp: '',
						nonceStr: '',
						package: '',
						signType: 'MD5',
						paySign: '',
						success(res) {},
						fail(res) {}
					})
					console.log('调用支付')
				} else {
					_this.showModal(res)
				}
			})
	},
	showModal: function(error) {
		wx.showModal({
			content: error.msg,
			showCancel: false,
		})
	},
	initValidate: function() {
		/** 4-2(配置规则)*/
		const rules = {
			money: {
				required: true,
				digits: true
			}
		}
		// 验证字段的提示信息，若不传则调用默认的信息
		const messages = {
			money: {
				required: '请输入缴纳金额',
				digits: '请输入数字'
			}
		}
		// 创建实例对象
		this.WxValidate = new WxValidate.WxValidate(rules, messages)
		/**
		 * 也可以自定义验证规则
		 */
		// 		this.WxValidate.addMethod('assistance', (value, param) => {
		// 			return this.WxValidate.optional(value) || (value.length >= 1 && value.length <= 2)
		// 		}, '请勾选 《顺风男服务协议》')
	}
})
